package com.base.engine.error;

public enum EMADErrorCode {

	GAME_REF,
	DISPLAY_MODE,
	CREATE_DISPLAY,
	INIT_GL,
	EXIT_GL,
	INIT_AL,
	EXIT_AL,
	EXIT_APPLICATION,
	INIT_COMPONENTS,
	INIT_GAME,
	GAME_LOOP,
	GENERAL_UPDATE,
	GENERAL_RENDERING,
	GENERAL_INPUT,
	RENDERING_RECTANGLE,
	CREATING_SHAPE,
	SAVE_GAME,
	LOAD_GAME
	; 
	
	public static String getErrorMessageByCode(EMADErrorCode code){
		switch(code){
		case GAME_REF: return "Game reference is invalid! Game was probably not correctly initialised." ; 
		case DISPLAY_MODE: return "Unable to find a display mode for setting up the game. ";
		case CREATE_DISPLAY: return "Fatal error occurred while creating the display! "; 
		case INIT_GL: return "An error occurred while creating the context for OpenGL. Try to restart the application." ; 
		case EXIT_GL: return "An error occurred while disabling the OpenGL context." ;
		case INIT_AL: return "An error occurred while creating the sound system. Try to restart the application." ; 
		case EXIT_AL: return "An error occurred while shutting down the sound system." ; 
		case EXIT_APPLICATION: return "Unable to close the application correctly." ; 
		case INIT_COMPONENTS: return "An error occurred while loading important components. Try to restart the application." ;
		case INIT_GAME: return "An error occurred while loading the game. Try to restart the application." ; 
		case GAME_LOOP: return "An error occurred during runtime! " ; 
		case GENERAL_UPDATE: return "Something went wrong during the updating procedure - Standby ..." ; 
		case GENERAL_RENDERING: return "Something went wrong during the rendering procedure - Standby ..." ; 
		case GENERAL_INPUT: return "Not receiving any correct input data anymore - Standby ... " ; 
		case RENDERING_RECTANGLE: return "Error while rendering a rectangle." ;
		case CREATING_SHAPE: return "Error while creating a basic shape." ; 
		case SAVE_GAME: return "An error occurred while trying to save the game. Unable to save the game correctly. " ; 
		case LOAD_GAME: return "An error occurred while trying to load the game. Unable to load the game correctly. " ; 
		default: return "An unexpected error occurred! Error Unidentified." ; 
		}
	}

	public static int getIDByCode(EMADErrorCode code){
		for(EMADErrorCode e: EMADErrorCode.values()){
			if(e.ordinal() == code.ordinal())
				return code.ordinal(); 
		}
		return -1 ; 
	}
	
	public static boolean isFatalError(EMADErrorCode code){
		switch(code){
		case GAME_REF: 			/* Fall through */ 
		case DISPLAY_MODE:
		case CREATE_DISPLAY: 
		case INIT_GL: 			
		case INIT_COMPONENTS:
		case INIT_GAME:
		case GAME_LOOP: return true ; 
		case EXIT_GL: 			/* Fall through */ 
		case EXIT_APPLICATION: 
		case GENERAL_UPDATE:
		case GENERAL_RENDERING:
		case GENERAL_INPUT: 
		case RENDERING_RECTANGLE:
		case CREATING_SHAPE:	return false ; 
		default: return false ;  
		}
	}
	
}
